import React from 'react'
import {useEffect,useState} from "react"
import {useDispatch,useSelector} from "react-redux"
import { Collapse } from 'react-vant';
function My() {
 let [newArr,setNewarr] = useState([])
 let store = useSelector(state=>({...state.reducer}))
 useEffect(()=>{
        let newstorearr = JSON.parse(JSON.stringify(store.arr))
        newstorearr.forEach((item)=>{
            let smallarr = item.children.filter(v=>{
               return  v.flag 
            })
            item.children = smallarr
        })
         console.log(newstorearr,"storearr");
         let aaa =  newstorearr.filter(item=>item.children.length)
         setNewarr(aaa)

 },[])

  return (
    <div>
        {
            newArr && newArr.length ? newArr.map((item,index)=>{
             return   (

                    <Collapse initExpanded={['1']} key={index}>
                         <Collapse.Item title={item.tit} name={index} key={index}> 
                             {
                                 item.children &&  item.children.length?  item.children.map((val,ind)=>{
                                    return <div  style={{borderBottom:"1px solid #ccc"}}key={ind}>{val.tit}  </div>
                                 }):"暂无数据"
                             }
                         
                         </Collapse.Item>
                    </Collapse>

                )
            }):""
        }
    </div>
  )
}

export default My